﻿using DelonixRegia.Classes;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DelonixRegia
{
    public partial class ViewShift : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnViewShift_Click(object sender, EventArgs e)
        {
            if (calendarShift.SelectedDates.Count == 1)
            {
                DateTime selectedDate = calendarShift.SelectedDate;
                string formattedDate = selectedDate.ToString("yyyy-MM-dd");
                string dayOfDate = selectedDate.ToString("dddd");
                DataTable shiftDT = StaffDBManager.getShiftByDay(formattedDate);

                if (shiftDT != null)
                {
                    gvShift.DataSource = shiftDT;
                    gvShift.DataBind();

                    if (dayOfDate.Equals("Monday"))
                    {
                        gvShift.Caption = "Shift on Monday, " + selectedDate.ToShortDateString();
                    }
                    else if (dayOfDate.Equals("Tuesday"))
                    {
                        gvShift.Caption = "Shift on Tuesday, " + selectedDate.ToShortDateString();
                    }
                    else if (dayOfDate.Equals("Wednesday"))
                    {
                        gvShift.Caption = "Shift on Wednesday, " + selectedDate.ToShortDateString();
                    }
                    else if (dayOfDate.Equals("Thursday"))
                    {
                        gvShift.Caption = "Shift on Thursday, " + selectedDate.ToShortDateString();
                    }
                    else if (dayOfDate.Equals("Friday"))
                    {
                        gvShift.Caption = "Shift on Friday, " + selectedDate.ToShortDateString();
                    }
                    else if (dayOfDate.Equals("Saturday"))
                    {
                        gvShift.Caption = "Shift on Saturday, " + selectedDate.ToShortDateString();
                    }
                    else if (dayOfDate.Equals("Sunday"))
                    {
                        gvShift.Caption = "Shift on Sunday, " + selectedDate.ToShortDateString();
                    }

                    pnlFirstStep.Visible = false;
                    pnlSecondStep.Visible = true;
                    Page.ClientScript.RegisterStartupScript(GetType(), "transitionToSecondStep", "transitionToSecondStep();", true);
                }
                else
                {
                    ClientScriptMgr.showErrorBox("Unable to find any shift on selected date!");
                }
            }
            else
            {
                ClientScriptMgr.showErrorBox("Please select a date first!");
            }
        }

        protected void btnGoBackPanel2_Click(object sender, EventArgs e)
        {
            calendarShift.SelectedDates.Clear();
            pnlSecondStep.Visible = false;
            pnlFirstStep.Visible = true;
            Page.ClientScript.RegisterStartupScript(GetType(), "transitionToFirstStep", "transitionToFirstStep();", true);
        }

        protected void CalendarShift_DayRender(object sender, DayRenderEventArgs e)
        {
            if (e.Day.IsOtherMonth)
            {
                e.Cell.BackColor = ColorTranslator.FromHtml("#a9a9a9");
                e.Cell.Visible = false;
                e.Cell.ForeColor = Color.White;
                e.Day.IsSelectable = false;
            }
        }
    }
}